2 Problem: 11517 - Exact Change
3 Author: Andrés Mejía-Posada
4 (http://blogaritmo.factorcomun.org)
6 Too much memory and too slow.
29 #define D(x) cout << #x " is " << x << endl
31 const int S
= 10005, N
= 105, oo
= INT_MAX
/ 4;
48 c
[0] = oo
; // Don't fuck
50 for (int i
=1; i
<=n
; ++i
){
55 //sum = min(sum, price);
58 for (int j
=1; j
<= sum
; ++j
) dp
[0][j
] = oo
;
60 for (int i
=1; i
<=n
; ++i
){
61 for (int j
=0; j
<=sum
; ++j
){
62 dp
[i
][j
] = dp
[i
-1][j
];
64 dp
[i
][j
] = min(dp
[i
][j
], dp
[i
-1][j
-c
[i
]] + 1);
70 for (int i=0; i<=n; ++i){
71 for (int j=0; j<=sum; ++j){
72 printf("%10d ", dp[i][j]);
78 for (int j
=price
; /*j <= sum*/; ++j
){
80 cout
<< j
<< " " << dp
[n
][j
] << endl
;